package models

//import "github.com/gin-gonic/gin"

type Sexam struct {
	Eno        string  `gorm:"cloumn:eno"`
	Smajor     string  `gorm:"column:smajor"`
	Sinterview string `gorm:"column:sinterview"`
	Scomputer  string `gorm:"column:scomputer"`
	Sscore     string `gorm:"column:sscore"`
}

func GetAllSexam(sexamParam map[string]interface{}) (error, []Sexam, int64) {
	var sexamData []Sexam
	page := sexamParam["page"].(int)
	pageSize := sexamParam["limit"].(int)
	searchText := sexamParam["searchText"].(string)
	var total int64
	err := db.Table("sexam").Where("eno like ?", "%"+searchText+"%").Order("sscore DESC").Count(&total).Find(&sexamData).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, sexamData, total
}

func AddSexam(sexamdata Sexam) (error, Sexam) {
	err := db.Table("sexam").Select("eno", "smajor", "sinterview", "scomputer","sscore").Create(&sexamdata).Error
	return err, sexamdata
}

func UpdateSexam(eno string, sexamdata Sexam) (error, Sexam) {
	err := db.Table("sexam").Where("eno = ?", sexamdata.Eno).Updates(&sexamdata).Error
	return err, sexamdata
}

func DeleteSexam(eno string) (error, Sexam) {
	var sexamdata Sexam
	sexamdata.Eno = eno
	err := db.Table("sexam").Where("eno = ?", eno).Find(&sexamdata).Delete(Sexam{}).Error
	return err, sexamdata
}

